package system.device;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import os.File;

import system.memory.RAM;
import cpu.components.CPU;
import cpu.datatypes.Word;

public class CardReaderTestBootloader {
	CPU cpu;
	RAM ram;
	
	private ui.Console console;
	private ui.Printer printer;
	
	@Before
	public void setUp() throws Exception {
		cpu =new CPU( console, printer );
		ram=new RAM(cpu.memoryunit, cpu.cacheunit);
	}

	@Test
	public void testPut() {
		File file=new File("loader");
		file.read();
		
		for (int j=0;j<file.buffer.length;j++)
		{
			char[] line=file.buffer[j].toCharArray();
			Word addressword=new Word();
			Word dataword=new Word();
			int actualValue;
			Word Address=new Word();
			int  expectedValue;
			for(int i=0;i<16;i++)
			{
				if(line[i]=='0')
					cpu.memoryunit.MAR.bit(i).value=false;
				else
					cpu.memoryunit.MAR.bit(i).value=true;
			}
			for(int i=16;i<32;i++)
			{
				if(line[i]=='0')
					cpu.memoryunit.MBR.bit(i-16).value=false;
				else
					cpu.memoryunit.MBR.bit(i-16).value=true;
			
			}
			actualValue=cpu.memoryunit.MBR.toJavaInt();
			Address.fromWord(cpu.memoryunit.MAR);
			
			
			cpu.memoryunit.put();
			cpu.memoryunit.MAR.fromWord(Address);
			cpu.memoryunit.get();
			expectedValue=cpu.memoryunit.MBR.toJavaInt();
				
			if (expectedValue!=actualValue)
				fail("Error in the Cardreader test "+expectedValue+"--"+actualValue);
			
		}	
		
	}

}
